Add a check for names starting with a digit
authorRahul Sharma <rsconceptx@gmail.com>
Sun, 15 Jan 2017 02:16:24 +0000 (07:46 +0530)
committerRahul Sharma <rsconceptx@gmail.com>
Sun, 15 Jan 2017 02:16:24 +0000 (07:46 +0530)
src/cargo/ops/cargo_new.rs

index 6b41f3ed5d3a1a793e7640f2e97c0188dd6c39e4..985d2f41add0e7de74c85c285ed01b149231e917 100644 (file)
@@ -135,6 +135,13 @@ fn check_name(name: &str) -> CargoResult<()> {
                name)
     }
 
+    if let Some(ref c) = name.chars().nth(0) {
+        if c.is_digit(10) {
+            bail!("Package names starting with a digit cannot be used as a crate name\n\
+               use --name to override crate name")
+        }
+    }
+
     for c in name.chars() {
         if c.is_alphanumeric() { continue }
         if c == '_' || c == '-' { continue }